{% extends 'base.html' %}

{% block title %}{{ organization.name }} - 组织详情 - 固定资产管理系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-12">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="{% url 'assets:index' %}">首页</a></li>
                <li class="breadcrumb-item"><a href="{% url 'assets:organization_list' %}">组织管理</a></li>
                <li class="breadcrumb-item active" aria-current="page">{{ organization.name }}</li>
            </ol>
        </nav>
        
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h2><i class="fas fa-building me-2"></i>{{ organization.name }}</h2>
            <div class="btn-group">
                <a href="{% url 'assets:organization_update' organization.pk %}" class="btn btn-primary">
                    <i class="fas fa-edit me-1"></i>编辑组织
                </a>
                <button type="button" class="btn btn-outline-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown">
                    <span class="visually-hidden">更多操作</span>
                </button>
                <ul class="dropdown-menu">
                    <li><a class="dropdown-item" href="{% url 'assets:department_list' %}?organization={{ organization.pk }}">
                        <i class="fas fa-sitemap me-2"></i>查看部门
                    </a></li>
                    <li><hr class="dropdown-divider"></li>
                    <li><a class="dropdown-item text-danger" href="{% url 'assets:organization_delete' organization.pk %}" onclick="return confirm('确定要删除组织 {{ organization.name }} 吗？')">
                        <i class="fas fa-trash me-2"></i>删除组织
                    </a></li>
                    <li><hr class="dropdown-divider"></li>
                    <li><a class="dropdown-item" href="{% url 'assets:organization_list' %}">
                        <i class="fas fa-arrow-left me-2"></i>返回列表
                    </a></li>
                </ul>
            </div>
        </div>

        <div class="row">
            <!-- 基本信息 -->
            <div class="col-md-8">
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="mb-0">
                            <i class="fas fa-info-circle me-2"></i>基本信息
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6">
                                <table class="table table-borderless">
                                    <tr>
                                        <td width="30%" class="text-muted">组织名称:</td>
                                        <td><strong>{{ organization.name }}</strong></td>
                                    </tr>
                                    <tr>
                                        <td class="text-muted">组织代码:</td>
                                        <td><code>{{ organization.code }}</code></td>
                                    </tr>
                                    <tr>
                                        <td class="text-muted">组织ID:</td>
                                        <td><code>{{ organization.pk }}</code></td>
                                    </tr>
                                </table>
                            </div>
                            <div class="col-md-6">
                                <table class="table table-borderless">
                                    <tr>
                                        <td width="30%" class="text-muted">创建时间:</td>
                                        <td>
                                            <i class="fas fa-calendar me-1 text-muted"></i>{{ organization.created_at|date:"Y-m-d H:i" }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="text-muted">更新时间:</td>
                                        <td>
                                            <i class="fas fa-clock me-1 text-muted"></i>{{ organization.updated_at|date:"Y-m-d H:i" }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="text-muted">状态:</td>
                                        <td>
                                            <span class="badge bg-success">
                                                <i class="fas fa-check me-1"></i>活跃
                                            </span>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        
                        {% if organization.description %}
                        <div class="mt-3">
                            <h6 class="text-muted">描述:</h6>
                            <p class="mb-0">{{ organization.description }}</p>
                        </div>
                        {% endif %}
                    </div>
                </div>
                
                <!-- 部门列表 -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="mb-0">
                            <i class="fas fa-sitemap me-2"></i>下属部门
                        </h5>
                    </div>
                    <div class="card-body">
                        {% if departments %}
                            <div class="table-responsive">
                                <table class="table table-sm">
                                    <thead class="table-light">
                                        <tr>
                                            <th>部门名称</th>
                                            <th>部门代码</th>
                                            <th>位置</th>
                                            <th>上级部门</th>
                                            <th>创建时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for department in departments %}
                                        <tr>
                                            <td>
                                                <div class="d-flex align-items-center">
                                                    <i class="fas fa-sitemap me-2 text-success"></i>
                                                    <strong>{{ department.name }}</strong>
                                                </div>
                                            </td>
                                            <td><span class="badge bg-info">{{ department.code }}</span></td>
                                            <td>
                                                {% if department.location %}
                                                    <i class="fas fa-map-marker-alt me-1 text-warning"></i>{{ department.location.name }}
                                                {% else %}
                                                    <span class="text-muted">-</span>
                                                {% endif %}
                                            </td>
                                            <td>
                                                {% if department.parent %}
                                                    {{ department.parent.name }}
                                                {% else %}
                                                    <span class="badge bg-primary">顶级部门</span>
                                                {% endif %}
                                            </td>
                                            <td>{{ department.created_at|date:"m-d H:i" }}</td>
                                            <td>
                                                <a href="{% url 'assets:department_detail' department.pk %}" class="btn btn-outline-info btn-sm" title="查看部门详情">
                                                    <i class="fas fa-eye"></i>
                                                </a>
                                            </td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        {% else %}
                            <div class="text-muted text-center py-3">
                                <i class="fas fa-sitemap fa-2x mb-2"></i>
                                <p class="mb-0">该组织暂无部门</p>
                                <a href="{% url 'assets:department_create' %}" class="btn btn-outline-primary btn-sm mt-2">
                                    <i class="fas fa-plus me-1"></i>创建部门
                                </a>
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>

            <!-- 统计信息 -->
            <div class="col-md-4">
                <!-- 组织状态卡片 -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="mb-0">
                            <i class="fas fa-chart-pie me-2"></i>组织概览
                        </h5>
                    </div>
                    <div class="card-body text-center">
                        <div class="mb-3">
                            <div class="alert alert-info">
                                <i class="fas fa-building fa-2x mb-2"></i>
                                <h5>{{ organization.name }}</h5>
                                <p class="mb-0">组织架构单位</p>
                            </div>
                        </div>
                        
                        <div class="row text-center">
                            <div class="col-6">
                                <h4 class="text-primary">{{ departments.count }}</h4>
                                <small class="text-muted">部门数</small>
                            </div>
                            <div class="col-6">
                                <h4 class="text-info">{{ total_assets }}</h4>
                                <small class="text-muted">资产数</small>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 快速操作 -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="mb-0">
                            <i class="fas fa-bolt me-2"></i>快速操作
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="d-grid gap-2">
                            <a href="{% url 'assets:department_create' %}" class="btn btn-success btn-sm">
                                <i class="fas fa-plus me-2"></i>创建部门
                            </a>
                            <a href="{% url 'assets:department_list' %}?organization={{ organization.pk }}" class="btn btn-info btn-sm">
                                <i class="fas fa-sitemap me-2"></i>查看所有部门
                            </a>
                            <a href="{% url 'assets:asset_list' %}?department__organization={{ organization.pk }}" class="btn btn-outline-primary btn-sm">
                                <i class="fas fa-cube me-2"></i>查看组织资产
                            </a>
                        </div>
                    </div>
                </div>
                
                <!-- 统计信息 -->
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">
                            <i class="fas fa-chart-bar me-2"></i>统计信息
                        </h5>
                    </div>
                    <div class="card-body">
                        <table class="table table-borderless table-sm">
                            <tr>
                                <td class="text-muted">组织ID:</td>
                                <td>
                                    <code>{{ organization.pk }}</code>
                                </td>
                            </tr>
                            <tr>
                                <td class="text-muted">部门数量:</td>
                                <td>
                                    <i class="fas fa-sitemap me-1 text-muted"></i>
                                    {{ departments.count }} 个部门
                                </td>
                            </tr>
                            <tr>
                                <td class="text-muted">资产数量:</td>
                                <td>
                                    <i class="fas fa-cube me-1 text-muted"></i>
                                    {{ total_assets }} 个资产
                                </td>
                            </tr>
                            <tr>
                                <td class="text-muted">用户数量:</td>
                                <td>
                                    <i class="fas fa-user me-1 text-muted"></i>
                                    {{ total_users }} 个用户
                                </td>
                            </tr>
                            <tr>
                                <td class="text-muted">创建时间:</td>
                                <td>
                                    <i class="fas fa-calendar me-1 text-muted"></i>
                                    {{ organization.created_at|date:"Y-m-d" }}
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}